import React from "react";

class App extends React.Component {
  state = {
    username: "admin",
    password: "admin",
  };

  handleChange(key) {
    // 返回的函数才是事件处理函数
    return (event) => {
      console.log("event", event);
      this.setState({
        [key]: event.target.value,
      });
    };
  }

  render() {
    const { username, password } = this.state;
    return (
      <div>
        <input
          type="text"
          value={username}
          onChange={this.handleChange("username")}
        />
        <br />
        <input
          type="text"
          value={password}
          onChange={this.handleChange("password")}
        />
      </div>
    );
  }
}

export default App;
